package com.taplinker.client.im.activity;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.taplinker.client.R;
import com.taplinker.client.im.domain.ImDataCenter;

public class FinishChatActivity extends Activity {
	private Button cancle;
	private TextView complete;
	private EditText remark;
	private boolean flag = true;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.chat_remark);
		findViews();
		initDatas();
	}

	private void initDatas() {
		cancle.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				finish();
			}
		});
		complete.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String reason = remark.getText().toString();
				if (!TextUtils.isEmpty(reason)) {
					Toast.makeText(FinishChatActivity.this, "正在提交数据,请稍等！",
							Toast.LENGTH_SHORT).show();
					ImDataCenter.getInstance().finishChat(reason,
							FinishChatActivity.this);
				} else {
					Toast.makeText(FinishChatActivity.this, "结束备注不能为空",
							Toast.LENGTH_LONG).show();
				}
			}
		});
		remark.selectAll();
		remark.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (flag) {
					flag = false;
					remark.setText("");
				}
			}
		});
	}

	private void findViews() {
		cancle = (Button) findViewById(R.id.title_left_bt);
		complete = (TextView) findViewById(R.id.title_right_bt);
		remark = (EditText) findViewById(R.id.add_remark_tv);

	}

	@Override
	protected void onDestroy() {
		cancle = null;
		complete = null;
		remark = null;
		super.onDestroy();
	}
}
